#ifndef NSBLUECOMMANDS__H_
#define NSBLUECOMMANDS__H_
#include <stdint.h>
#include <sys/time.h>
#include "nsblueapi.h"

#define BLUEMAXDATALEN 333

#define STX 0x02
#define ETX 0x03

#define PACKET_TYPE_REQUEST 0x52
#define PACKET_TYPE_CONFIRM 0x43
#define PACKET_TYPE_INDICATION 0x69
#define PACKET_TYPE_RESPONSE 0x72

#define GAP_INQUIRY 0x00
#define GAP_DEVICE_FOUND 0x01
#define GAP_REMOTE_DEVICE_NAME 0x02
#define GAP_READ_LOCAL_NAME 0x03
#define GAP_WRITE_LOCAL_NAME 0x04
#define GAP_READ_LOCAL_BDA 0x05
#define GAP_SET_SCANMODE 0x06
#define GAP_GET_FIXED_PIN 0x16
#define GAP_SET_FIXED_PIN 0x17
#define GAP_GET_PIN 0x75
#define GAP_GET_SECURITY_MODE 0x18
#define GAP_SET_SECURITY_MODE 0x19
#define GAP_REMOVE_PAIRING 0x1B
#define GAP_LIST_PAIRED_DEVICES 0x1C
#define GAP_ENTER_SNIFF_MODE 0x21
#define GAP_EXIT_SNIFF_MODE 0x37
#define GAP_ENTER_PARK_MODE 0x38
#define GAP_EXIT_PARK_MODE 0x39
#define GAP_ENTER_HOLD_MODE 0x3A
#define GAP_SET_LINK_POLICY 0x3B
#define GAP_GET_LINK_POLICY 0x3C
#define GAP_POWER_SAVE_MODE_CHANGED 0x3D
#define GAP_ACL_ESTABLISHED 0x50
#define GAP_ACL_TERMINATED 0x51
#define GAP_SET_AUDIO_CONFIG 0x59
#define GAP_GET_AUDIO_CONFIG 0x5A
#define GAP_ESTABLISH_SCO_LINK 0x5D
#define GAP_RELEASE_SCO_LINK 0x5E
#define GAP_MUTE_MIC 0x5F
#define GAP_SET_VOLUME 0x60
#define GAP_GET_VOLUME 0x61
#define GAP_CHANGE_SCO_PACKET_TYPE 0x62
#define SPP_SET_PORT_CONFIG 0x07
#define SPP_GET_PORT_CONFIG 0x08
#define SPP_PORT_CONFIG_CHANGED 0x09
#define SPP_ESTABLISH_LINK 0x0A
#define SPP_LINK_ESTABLISHED 0x0B
#define SPP_INCOMMING_LINK_ESTABLISHED 0x0C
#define SPP_RELEASE_LINK 0x0D
#define SPP_LINK_RELEASED 0x0E
#define SPP_SEND_DATA 0x0F
#define SPP_INCOMING_DATA 0x10
#define SPP_TRANSPARENT_MODE 0x11
#define SPP_CONNECT_DEFAULT_CON 0x12
#define SPP_STORE_DEFAULT_CON 0x13
#define SPP_GET_LIST_DEFAULT_CON 0x14
#define SPP_DELETE_DEFAULT_CON 0x15
#define SPP_SET_LINK_TIMEOUT 0x57
#define SPP_GET_LINK_TIMEOUT 0x58
#define SPP_PORT_STATUS_CHANGED 0x3E
#define SPP_GET_PORT_STATUS 0x40
#define SPP_PORT_SET_DTR 0x41
#define SPP_PORT_SET_RTS 0x42
#define SPP_PORT_BREAK 0x43
#define SPP_PORT_OVERRUN_ERROR 0x44
#define SPP_PORT_PARITY_ERROR 0x45
#define SPP_PORT_FRAMING_ERROR 0x46
#define SDAP_CONNECT 0x32
#define SDAP_DISCONNECT 0x33
#define SDAP_CONNECTION_LOST 0x34
#define SDAP_SERVICE_BROWSE 0x35
#define SDAP_SERVICE_SEARCH 0x36
#define SDAP_SERVICE_REQUEST 0x1E
#define SDAP_ATTRIBUTE_REQUEST 0x3F
#define CHANGE_LOCAL_BDADDRESS 0x27
#define CHANGE_NVS_UART_SPEED 0x23
#define CHANGE_UART_SETTINGS 0x48
#define SET_PORTS_TO_OPEN 0x22
#define GET_PORTS_TO_OPEN 0x1F
#define RESTORE_FACTORY_SETTINGS 0x1A
#define STORE_CLASS_OF_DEVICE 0x28
#define FORCE_MASTER_ROLE 0x1D
#define READ_OPERATION_MODE 0x49
#define WRITE_OPERATION_MODE 0x4A
#define SET_DEFAULT_LINK_POLICY 0x4C
#define GET_DEFAULT_LINK_POLICY 0x4D
#define SET_EVENT_FILTER 0x4E
#define GET_EVENT_FILTER 0x4F
#define SET_DEFAULT_LINK_TIMEOUT 0x55
#define GET_DEFAULT_LINK_TIMEOUT 0x56
#define SET_DEFAULT_AUDIO_CONFIG 0x5B
#define GET_DEFAULT_AUDIO_CONFIG 0x5C
#define SET_DEFAULT_LINK_LATENCY 0x63
#define GET_DEFAULT_LINK_LATENCY 0x64
#define SET_CLOCK_FREQUENCY 0x67
#define GET_CLOCK_FREQUENCY 0x68
#define SET_PCM_SLAVE_CONFIG 0x74
#define ENABLE_SDP_RECORD 0x29
#define DELETE_SDP_RECORDS 0x2A
#define STORE_SDP_RECORD 0x31
#define RESET 0x26
#define DEVICE_READY 0x25
#define TEST_MODE 0x24
#define WRITE_ROM_PATCH 0x47
#define READ_RSSI 0x20
#define RF_TEST_MODE 0x4B
#define DISABLE_TL 0x52
#define TL_ENABLED 0x53
#define HCI_COMMAND 0x65
#define AWAIT_INITIALIZATION_EVENT 0x66
#define ENTER_BLUETOOTH_MODE 0x66
#define SET_CLOCK_AND_BAUDRATE 0x69
#define SET_GPIO_WPU 0x6B
#define GET_GPIO_STATE 0x6C
#define SET_GPIO_DIRECTION 0x6D
#define SET_GPIO_OUTPUT_HIGH 0x6E
#define SET_GPIO_OUTPUT_LOW 0x6F
#define READ_NVS 0x72
#define WRITE_NVS 0x73

#define NOOPCODE 0x90
#define NUMOPCODE 0x80

/* Generic Error Codes */
#define ERROR_OK 0x00
#define ERROR_INVALID_NO_OF_PARAMETERS 0x01
#define ERROR_DURATION_OUT_OF_RANGE 0x02
#define ERROR_INVALID_MODE 0x03
#define ERROR_TIMEOUT 0x04
#define ERROR_UNKNOWN_ERROR 0x05
#define ERROR_NAME_TOO_LONG 0x06
#define ERROR_INVALID_DISCOVERABILITY_PARAMETER 0x07
#define ERROR_INVALID_CONNECTABILITY_PARAMETER 0x08
#define ERROR_INVALID_SECURITY_MODE 0x09
#define ERROR_LINKKEY_DOES_NOT_EXISTS 0x0a
#define ERROR_CONNECTION_FAILED 0x0b
#define ERROR_TRUNCATED_ANSWER 0x0c
#define ERROR_RESULT_TOO_LARGE 0x0d
#define ERROR_NOT_POSSIBLE_TO_ENTER_TESTMODE 0x0e
#define ERROR_ILLEGAL_TESTMODE 0x0f 
#define ERROR_RESET_TO_NSC_BDADDRESS 0x10
#define ERROR_UART_SPEED_OUT_OF_RANGE 0x11
#define ERROR_INVALID_PORT 0x12
#define ERROR_ILLEGAL_STATE_VALUE 0x13
#define ERROR_IDENTIFIER_OUT_OF_RANGE 0x14
#define ERROR_RECORD_ALREADY_IN_SELECTED_STATE 0x15
#define ERROR_INVALID_AUTHENTICATION_VALUE 0x16
#define ERROR_INVALID_ENCRYPTION_VALUE 0x17
#define ERROR_MAXIMUM_NO_OF_SERVICE_RECORDS_REACHED 0x18
#define ERROR_WRITING_TO_NVS 0x19
#define ERROR_INVALID_ROLE 0x1a
#define ERROR_LIMIT 0x1b
#define ERROR_UNEXPECTED 0x1c
#define ERROR_UNABLE_TO_SEND 0x1d
#define ERROR_CURRENTLY_NO_BUFFER 0x1e
#define ERROR_NO_CONNECTION 0x1f 
#define ERROR_SPP_INVALID_PORT 0x20
#define ERROR_SPP_PORT_NOT_OPEN 0x21
#define ERROR_SPP_PORT_BUSY 0x22
#define ERROR_SPP_MULTIPLE_CONNECTIONS 0x23
#define ERROR_SPP_MULTIPLE_TRANSPARENT 0x24
#define ERROR_SPP_DEFAULT_CONNECTION_NOT_STORED 0x25
#define ERROR_SPP_AUTOMATIC_CONNECTIONS_PROGRESSING 0x26
#define ERROR_UNSPECIFIED_ERROR 0x27
#define ERROR_IDENTIFIER_NOT_IN_USE 0x28
#define ERROR_INVALID_SUPPORTED_FAXCLASS_VALUE 0x29
#define ERROR_TOO_MANY_SUPPORTED_FORMATS 0x2a
#define ERROR_TOO_MANY_DATASTORES 0x2b
#define ERROR_ATTEMPT_FAILED 0x2C
#define ERROR_ILLEGAL_LINK_POLICY 0x2D
#define ERROR_PINCODE_TOO_LONG 0x2E
#define ERROR_PARITY_BIT_OUT_OF_RANGE 0x2F
#define ERROR_STOP_BITS_OUT_OF_RANGE 0x30
#define ERROR_ILLEGAL_LINK_TIMEOUT 0x31
#define ERROR_COMMAND_DISALLOWED 0x32
#define ERROR_ILLEGAL_AUDIO_CODEC_TYPE 0x33
#define ERROR_ILLEGAL_AUDIO_AIR_FORMAT 0x34
#define ERROR_SDP_RECORD_TOO_LONG 0x35
#define ERROR_SDP_FAILED_TO_CREATE_RECORD 0x36
#define ERROR_SET_VOLUME_FAILED 0x37
#define ERROR_ILLEGAL_PACKET_TYPE 0x38
#define ERROR_INVALID_CODEC_SETTING 0x39

RETURN_VALUE_T sendPacket(int nsb_serfd, uint8_t type, uint8_t opcode, uint8_t * data, uint16_t dataLen);
RETURN_VALUE_T getPacket(int nsb_serfd, uint8_t * type, uint8_t * opcode, uint8_t * data, uint16_t * dataLen);

#endif
